package com.atguigu.lease.web.admin.service.impl;

import com.atguigu.lease.model.entity.*;
import com.atguigu.lease.web.admin.mapper.*;
import com.atguigu.lease.web.admin.service.*;
import com.atguigu.lease.web.admin.vo.agreement.AgreementQueryVo;
import com.atguigu.lease.web.admin.vo.agreement.AgreementVo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fasterxml.jackson.databind.annotation.JsonAppend;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author liubo
 * @description 针对表【lease_agreement(租约信息表)】的数据库操作Service实现
 * @createDate 2023-07-24 15:48:00
 */
@Service
public class LeaseAgreementServiceImpl extends ServiceImpl<LeaseAgreementMapper, LeaseAgreement>
        implements LeaseAgreementService {
@Autowired
private RoomInfoService roomInfoService;
@Autowired
private LeaseTermService leaseTermService;
@Autowired
private PaymentTypeService paymentTypeService;
@Autowired
private LeaseAgreementMapper leaseAgreementMapper;

@Autowired
private ApartmentInfoMapper apartmentInfoMapper;

@Autowired
private RoomInfoMapper roomInfoMapper;
@Autowired
private PaymentTypeMapper paymentTypeMapper;

@Autowired
private LeaseTermMapper leaseTermMapper;
    @Override
    public void queryPage(IPage<AgreementVo> page, AgreementQueryVo queryVo) {
         leaseAgreementMapper.queryPage(page,queryVo);
    }

    @Override
    public AgreementVo customGetById(Long id) {
        //1.查询租约单表信息,若为空,则被其他管理员删除,返回null
        LeaseAgreement leaseAgreement = getById(id);
        if (leaseAgreement==null){
            return null;
        }
        //2.查询签约公寓信息
        ApartmentInfo apartmentInfo = apartmentInfoMapper.selectById(leaseAgreement.getApartmentId());
        
        //3.查询签约房间信息
        RoomInfo roomInfo = roomInfoMapper.selectById(leaseAgreement.getRoomId());
        
        //4.查询支付方式
        PaymentType paymentType = paymentTypeMapper.selectById(leaseAgreement.getPaymentTypeId());
        
        //5.查询租期
        LeaseTerm leaseTerm = leaseTermMapper.selectById(leaseAgreement.getLeaseTermId());

        //6.合并到AgreementVo里
        AgreementVo agreementVo = new AgreementVo();
        BeanUtils.copyProperties(leaseAgreement,agreementVo);
        agreementVo.setLeaseTerm(leaseTerm);
        agreementVo.setPaymentType(paymentType);
        agreementVo.setRoomInfo(roomInfo);
        agreementVo.setApartmentInfo(apartmentInfo);
        return agreementVo;
    }


}




